package day03;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/4/9
 */
public class Test05 {
    public static void main(String[] args) {
        int count = 0; // 统计水仙花数的个数
        System.out.println("100-999之间的水仙花数有：");
        for (int num = 100; num <= 999; num++) {
            int hundreds = num / 100;      // 获取百位数
            int tens = (num / 10) % 10;    // 获取十位数
            int ones = num % 10;          // 获取个位数
            // 计算各位数字的立方和
            int sum = hundreds * hundreds * hundreds
                    + tens * tens * tens
                    + ones * ones * ones;
            // 判断是否为水仙花数
            if (sum == num) {
                System.out.print(num + " ");
                count++;
            }
        }
        System.out.println("\n水仙花数共有：" + count + "个");
    }
}
